<?php
/*
 * Author:  Somnath Shinde- soma.shinde@gmail.com Mobile No:- 9423792564
 * 
 * Create Date: 
 * 
 * Version of MYSQL_to_PHP: 1.1
 * 
 * Ranzani( YZ'S );
 * 
 */
require_once 'Base/BaseUsers.class.php';

Class Users {

	public function  __construct() {
			if( true == isset( $_SERVER['connection'] ) ) {
				$this->connection = $_SERVER['connection'];
			}
	}

	
	/*******************************************************************************************
	******************************** Fetch Functions *******************************************
	*******************************************************************************************/

	public function fetchSql( $strSql ) {
		$result = $this->connection->RunQuery( $strSql );
		$arrobjUsers = array();
		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objUsers = new BaseUsers();
			$objUsers->setId( ( true == isset( $row["id"] ) ) ? $row["id"] : 'NULL' );
			$objUsers->setName( ( true == isset( $row["Name"] ) ) ? $row["Name"] : 'NULL' );
			$objUsers->setEmail( ( true == isset( $row["Email"] ) ) ? $row["Email"] : 'NULL' );
			$objUsers->setLogin( ( true == isset( $row["Login"] ) ) ? $row["Login"] : 'NULL' );
			$objUsers->setPassword( ( true == isset( $row["Password"] ) ) ? $row["Password"] : 'NULL' );
			$objUsers->setDepartment( ( true == isset( $row["department"] ) ) ? $row["department"] : 'NULL' );
			$objUsers->setReportingMgr( ( true == isset( $row["reporting_mgr"] ) ) ? $row["reporting_mgr"] : 'NULL' );
			$objUsers->setDtOfjoin( ( true == isset( $row["dt_ofjoin"] ) ) ? $row["dt_ofjoin"] : 'NULL' );
			$objUsers->setDtOfleave( ( true == isset( $row["dt_ofleave"] ) ) ? $row["dt_ofleave"] : 'NULL' );
			$objUsers->setTenure( ( true == isset( $row["tenure"] ) ) ? $row["tenure"] : 'NULL' );
			$objUsers->setBillingStatus( ( true == isset( $row["billing_status"] ) ) ? $row["billing_status"] : 'NULL' );
			$objUsers->setEmpStatus( ( true == isset( $row["emp_status"] ) ) ? $row["emp_status"] : 'NULL' );
			$objUsers->setEmpShiftStart( ( true == isset( $row["emp_shift_start"] ) ) ? $row["emp_shift_start"] : 'NULL' );
			$objUsers->setEmpShiftEnd( ( true == isset( $row["emp_shift_end"] ) ) ? $row["emp_shift_end"] : 'NULL' );
			$objUsers->setLockout( ( true == isset( $row["lockout"] ) ) ? $row["lockout"] : 'NULL' );
			$objUsers->setLockouttime( ( true == isset( $row["lockouttime"] ) ) ? $row["lockouttime"] : 'NULL' );
			$objUsers->setUnlocktime( ( true == isset( $row["unlocktime"] ) ) ? $row["unlocktime"] : 'NULL' );
			$objUsers->setAdmin( ( true == isset( $row["admin"] ) ) ? $row["admin"] : 'NULL' );
			$objUsers->setBanned( ( true == isset( $row["banned"] ) ) ? $row["banned"] : 'NULL' );
			$objUsers->setGrp( ( true == isset( $row["grp"] ) ) ? $row["grp"] : 'NULL' );
			$objUsers->setNAccessLevel( ( true == isset( $row["nAccessLevel"] ) ) ? $row["nAccessLevel"] : 'NULL' );
			$objUsers->setCabStatus( ( true == isset( $row["cab_status"] ) ) ? $row["cab_status"] : 'NULL' );
			$objUsers->setAddress( ( true == isset( $row["address"] ) ) ? $row["address"] : 'NULL' );
			$objUsers->setShiftIn( ( true == isset( $row["shift_in"] ) ) ? $row["shift_in"] : 'NULL' );
			$objUsers->setMailStatus( ( true == isset( $row["mail_status"] ) ) ? $row["mail_status"] : 'NULL' );
			array_push( $arrobjUsers, $objUsers );
		}
		return $arrobjUsers;
	}
	public function fetchAllUsers() {
		$result = $this->connection->RunQuery("SELECT * FROM USERS");
		$arrobjUsers = array();
		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objUsers = new BaseUsers();
			$objUsers->setId( ( true == isset( $row["id"] ) ) ? $row["id"] : 'NULL' );
			$objUsers->setName( ( true == isset( $row["Name"] ) ) ? $row["Name"] : 'NULL' );
			$objUsers->setEmail( ( true == isset( $row["Email"] ) ) ? $row["Email"] : 'NULL' );
			$objUsers->setLogin( ( true == isset( $row["Login"] ) ) ? $row["Login"] : 'NULL' );
			$objUsers->setPassword( ( true == isset( $row["Password"] ) ) ? $row["Password"] : 'NULL' );
			$objUsers->setDepartment( ( true == isset( $row["department"] ) ) ? $row["department"] : 'NULL' );
			$objUsers->setReportingMgr( ( true == isset( $row["reporting_mgr"] ) ) ? $row["reporting_mgr"] : 'NULL' );
			$objUsers->setDtOfjoin( ( true == isset( $row["dt_ofjoin"] ) ) ? $row["dt_ofjoin"] : 'NULL' );
			$objUsers->setDtOfleave( ( true == isset( $row["dt_ofleave"] ) ) ? $row["dt_ofleave"] : 'NULL' );
			$objUsers->setTenure( ( true == isset( $row["tenure"] ) ) ? $row["tenure"] : 'NULL' );
			$objUsers->setBillingStatus( ( true == isset( $row["billing_status"] ) ) ? $row["billing_status"] : 'NULL' );
			$objUsers->setEmpStatus( ( true == isset( $row["emp_status"] ) ) ? $row["emp_status"] : 'NULL' );
			$objUsers->setEmpShiftStart( ( true == isset( $row["emp_shift_start"] ) ) ? $row["emp_shift_start"] : 'NULL' );
			$objUsers->setEmpShiftEnd( ( true == isset( $row["emp_shift_end"] ) ) ? $row["emp_shift_end"] : 'NULL' );
			$objUsers->setLockout( ( true == isset( $row["lockout"] ) ) ? $row["lockout"] : 'NULL' );
			$objUsers->setLockouttime( ( true == isset( $row["lockouttime"] ) ) ? $row["lockouttime"] : 'NULL' );
			$objUsers->setUnlocktime( ( true == isset( $row["unlocktime"] ) ) ? $row["unlocktime"] : 'NULL' );
			$objUsers->setAdmin( ( true == isset( $row["admin"] ) ) ? $row["admin"] : 'NULL' );
			$objUsers->setBanned( ( true == isset( $row["banned"] ) ) ? $row["banned"] : 'NULL' );
			$objUsers->setGrp( ( true == isset( $row["grp"] ) ) ? $row["grp"] : 'NULL' );
			$objUsers->setNAccessLevel( ( true == isset( $row["nAccessLevel"] ) ) ? $row["nAccessLevel"] : 'NULL' );
			$objUsers->setCabStatus( ( true == isset( $row["cab_status"] ) ) ? $row["cab_status"] : 'NULL' );
			$objUsers->setAddress( ( true == isset( $row["address"] ) ) ? $row["address"] : 'NULL' );
			$objUsers->setShiftIn( ( true == isset( $row["shift_in"] ) ) ? $row["shift_in"] : 'NULL' );
			$objUsers->setMailStatus( ( true == isset( $row["mail_status"] ) ) ? $row["mail_status"] : 'NULL' );
			array_push( $arrobjUsers, $objUsers);
		}
		return $arrobjUsers;
	}
	public function fetchAllUsersByIds( $arrintIds ) {
		$result = $this->connection->RunQuery("SELECT * FROM USERS WHERE id IN ( implode( "," $arrintIds ) " );
		$arrobjUsers = array();
		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objUsers->setId( ( true == isset( $row["id"] ) ) ? $row["id"] : 'NULL' );
			$objUsers->setName( ( true == isset( $row["Name"] ) ) ? $row["Name"] : 'NULL' );
			$objUsers->setEmail( ( true == isset( $row["Email"] ) ) ? $row["Email"] : 'NULL' );
			$objUsers->setLogin( ( true == isset( $row["Login"] ) ) ? $row["Login"] : 'NULL' );
			$objUsers->setPassword( ( true == isset( $row["Password"] ) ) ? $row["Password"] : 'NULL' );
			$objUsers->setDepartment( ( true == isset( $row["department"] ) ) ? $row["department"] : 'NULL' );
			$objUsers->setReportingMgr( ( true == isset( $row["reporting_mgr"] ) ) ? $row["reporting_mgr"] : 'NULL' );
			$objUsers->setDtOfjoin( ( true == isset( $row["dt_ofjoin"] ) ) ? $row["dt_ofjoin"] : 'NULL' );
			$objUsers->setDtOfleave( ( true == isset( $row["dt_ofleave"] ) ) ? $row["dt_ofleave"] : 'NULL' );
			$objUsers->setTenure( ( true == isset( $row["tenure"] ) ) ? $row["tenure"] : 'NULL' );
			$objUsers->setBillingStatus( ( true == isset( $row["billing_status"] ) ) ? $row["billing_status"] : 'NULL' );
			$objUsers->setEmpStatus( ( true == isset( $row["emp_status"] ) ) ? $row["emp_status"] : 'NULL' );
			$objUsers->setEmpShiftStart( ( true == isset( $row["emp_shift_start"] ) ) ? $row["emp_shift_start"] : 'NULL' );
			$objUsers->setEmpShiftEnd( ( true == isset( $row["emp_shift_end"] ) ) ? $row["emp_shift_end"] : 'NULL' );
			$objUsers->setLockout( ( true == isset( $row["lockout"] ) ) ? $row["lockout"] : 'NULL' );
			$objUsers->setLockouttime( ( true == isset( $row["lockouttime"] ) ) ? $row["lockouttime"] : 'NULL' );
			$objUsers->setUnlocktime( ( true == isset( $row["unlocktime"] ) ) ? $row["unlocktime"] : 'NULL' );
			$objUsers->setAdmin( ( true == isset( $row["admin"] ) ) ? $row["admin"] : 'NULL' );
			$objUsers->setBanned( ( true == isset( $row["banned"] ) ) ? $row["banned"] : 'NULL' );
			$objUsers->setGrp( ( true == isset( $row["grp"] ) ) ? $row["grp"] : 'NULL' );
			$objUsers->setNAccessLevel( ( true == isset( $row["nAccessLevel"] ) ) ? $row["nAccessLevel"] : 'NULL' );
			$objUsers->setCabStatus( ( true == isset( $row["cab_status"] ) ) ? $row["cab_status"] : 'NULL' );
			$objUsers->setAddress( ( true == isset( $row["address"] ) ) ? $row["address"] : 'NULL' );
			$objUsers->setShiftIn( ( true == isset( $row["shift_in"] ) ) ? $row["shift_in"] : 'NULL' );
			$objUsers->setMailStatus( ( true == isset( $row["mail_status"] ) ) ? $row["mail_status"] : 'NULL' );
			array_push( $arrobjUsers, $objUsers );
		}
		return $arrobjUsers;
	}

	public function fetchUsersById( $intId ) {
		$result = $this->connection->RunQuery( "SELECT * FROM USERS WHERE id = " . $intId );
			$objUsers = NULL;
		while($row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objUsers = new BaseUsers();
			$objUsers->setId( ( true == isset( $row["id"] ) ) ? $row["id"] : 'NULL' );
			$objUsers->setName( ( true == isset( $row["Name"] ) ) ? $row["Name"] : 'NULL' );
			$objUsers->setEmail( ( true == isset( $row["Email"] ) ) ? $row["Email"] : 'NULL' );
			$objUsers->setLogin( ( true == isset( $row["Login"] ) ) ? $row["Login"] : 'NULL' );
			$objUsers->setPassword( ( true == isset( $row["Password"] ) ) ? $row["Password"] : 'NULL' );
			$objUsers->setDepartment( ( true == isset( $row["department"] ) ) ? $row["department"] : 'NULL' );
			$objUsers->setReportingMgr( ( true == isset( $row["reporting_mgr"] ) ) ? $row["reporting_mgr"] : 'NULL' );
			$objUsers->setDtOfjoin( ( true == isset( $row["dt_ofjoin"] ) ) ? $row["dt_ofjoin"] : 'NULL' );
			$objUsers->setDtOfleave( ( true == isset( $row["dt_ofleave"] ) ) ? $row["dt_ofleave"] : 'NULL' );
			$objUsers->setTenure( ( true == isset( $row["tenure"] ) ) ? $row["tenure"] : 'NULL' );
			$objUsers->setBillingStatus( ( true == isset( $row["billing_status"] ) ) ? $row["billing_status"] : 'NULL' );
			$objUsers->setEmpStatus( ( true == isset( $row["emp_status"] ) ) ? $row["emp_status"] : 'NULL' );
			$objUsers->setEmpShiftStart( ( true == isset( $row["emp_shift_start"] ) ) ? $row["emp_shift_start"] : 'NULL' );
			$objUsers->setEmpShiftEnd( ( true == isset( $row["emp_shift_end"] ) ) ? $row["emp_shift_end"] : 'NULL' );
			$objUsers->setLockout( ( true == isset( $row["lockout"] ) ) ? $row["lockout"] : 'NULL' );
			$objUsers->setLockouttime( ( true == isset( $row["lockouttime"] ) ) ? $row["lockouttime"] : 'NULL' );
			$objUsers->setUnlocktime( ( true == isset( $row["unlocktime"] ) ) ? $row["unlocktime"] : 'NULL' );
			$objUsers->setAdmin( ( true == isset( $row["admin"] ) ) ? $row["admin"] : 'NULL' );
			$objUsers->setBanned( ( true == isset( $row["banned"] ) ) ? $row["banned"] : 'NULL' );
			$objUsers->setGrp( ( true == isset( $row["grp"] ) ) ? $row["grp"] : 'NULL' );
			$objUsers->setNAccessLevel( ( true == isset( $row["nAccessLevel"] ) ) ? $row["nAccessLevel"] : 'NULL' );
			$objUsers->setCabStatus( ( true == isset( $row["cab_status"] ) ) ? $row["cab_status"] : 'NULL' );
			$objUsers->setAddress( ( true == isset( $row["address"] ) ) ? $row["address"] : 'NULL' );
			$objUsers->setShiftIn( ( true == isset( $row["shift_in"] ) ) ? $row["shift_in"] : 'NULL' );
			$objUsers->setMailStatus( ( true == isset( $row["mail_status"] ) ) ? $row["mail_status"] : 'NULL' );
		}
		return $objUsers;
	}

	public function GetKeysOrderBy($column, $order){
		$keys = array(); $i = 0;
		$result = $this->connection->RunQuery("SELECT id from users order by $column $order");
			while($row = $result->fetch_array(MYSQLI_ASSOC)){
				$keys[$i] = $row["id"];
				$i++;
			}
	return $keys;
	}

	public function endUsers(){
		$this->connection->CloseMysql();
	}

}